﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ee_wp_tourmaker.WebServices;

namespace ee_wp_tourmaker
{
    public partial class ProfilePivot : PhoneApplicationPage
    {
        public ProfilePivot()
        {
            InitializeComponent();
            nameTextBlock.Text = App.ProfileData.Name;
            highscoresListBox.ItemsSource = App.ProfileData.playerList;
        }

        private void enterNameTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                enterNameTextBox.Visibility = System.Windows.Visibility.Collapsed;
                nameTextBlock.Text = enterNameTextBox.Text;
                enterNameTextBox.Text = "";
                App.MainModel.Changes.Items.Add(new AzureService.SyncItem() { EditPerson = new AzureService.EditPerson() 
                { Id = App.ProfileData.Id, Name = nameTextBlock.Text }, ItemType = AzureService.SyncItemType.EditPerson });
                var saveChangesService = new SaveChangesService();
                saveChangesService.SaveChangesStart();
            }
        }

        private void nameTextBlock_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            enterNameTextBox.Visibility = System.Windows.Visibility.Visible;
        }
    }
}
